<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateNotificationsTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('notifications', function (Blueprint $table) {
            $table->bigIncrements('id')->unsigned();
            $table->unsignedBigInteger('user_id')->comment('接收用户ID')->index();
            $table->string('type', 50)->comment('通知类型')->index();
            $table->string('title')->comment('通知标题');
            $table->text('content')->comment('通知内容');
            $table->json('data')->comment('附加数据')->nullable();
            $table->boolean('read')->default(false)->comment('是否已读')->index();
            $table->timestamp('read_at')->nullable()->comment('阅读时间');
            $table->timestamps();

            $table->index('created_at');

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

            $table->comment('通知表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('notifications');
    }
}
